package com.hnu.store.controller;

import com.hnu.store.entity.Feedback;
import com.hnu.store.service.IFeedbackService;
import com.hnu.store.utils.JsonResult;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统反馈Controller
 */
@RestController
@CrossOrigin

@RequestMapping("feedback")
public class FeedbackController extends BaseController{
    @Autowired
    private IFeedbackService feedbackService;

    /**
     * 获取所有反馈（管理员）
     * @return Feedback类型的list
     */
    @RequestMapping("getAllFeedback")
    public JsonResult getAllFeedback(){
        List<Feedback> feedbackList=feedbackService.getAllFeedback();
        JsonResult result=new JsonResult(OK);
        result.addData("feedbackList",feedbackList);
        return result;
    }

    /**
     * 获取该用户的所有反馈
     * @param userId 用户id
     * @return Feedback类型的list
     */
    @RequestMapping("getFeedbackListById")
    public JsonResult getFeedbackListByUserId(Integer userId){
        List<Feedback> feedbackList=feedbackService.getFeedbackListByUserid(userId);
        JsonResult result=new JsonResult(OK);
        result.addData("feedbackList",feedbackList);
        return result;
    }

    /**
     * 根据id获取单个feedback对象
     * @param feedbackId
     * @return
     */
    @RequestMapping("getFeedbackById")
    public JsonResult getFeedbackById(Integer feedbackId){
        Feedback feedback=feedbackService.getFeedbackById(feedbackId);
        JsonResult result=new JsonResult(OK);
        result.addData("feedback",feedback);
        return result;
    }

    /**
     * 给指定id的反馈添加回复
     * @param feedbackId 系统反馈id
     * @param content 回复内容
     * @return 200
     */
    @RequestMapping("replyFeedback")
    public JsonResult insertReply(Integer feedbackId, String content){
        feedbackService.addContent(feedbackId,content);
        JsonResult result=new JsonResult(OK);
        return result;
    }

    /**
     * 插入系统反馈记录
     * @param feedback(userId, fileId, fileUrl, feedType, isReplied(0), feedTxt)
     * @return 200
     */
    @RequestMapping("addFeedback")
    public JsonResult addFeedback(Feedback feedback){
        feedbackService.insert(feedback);
        JsonResult result=new JsonResult(OK);
        return result;
    }
}
